import os
import sys


def resource_path(relative_path):
    """动态获取资源绝对路径（兼容开发环境和PyInstaller打包环境）"""
    if getattr(sys, 'frozen', False):  # 检测是否在打包环境中运行
        base_path = getattr(sys, '_MEIPASS', '.')  # 资源被解压到临时目录
    else:
        base_path = os.path.dirname(os.path.abspath(__file__))  # 开发环境使用当前目录
    full_path = os.path.join(base_path, relative_path)
    return os.path.normpath(full_path)
